#include "window-main.h"
#include "window-room.h"
#include "window-create.h"

void
window_main_button_join_cb(GtkButton *button,
						   gpointer data)
{
	struct window_main_s *window = (struct window_main_s *)data;

	window_room_init();
}

void
window_main_button_create_cb(GtkButton *button,
						   gpointer data)
{
	window_create_init();
}

void
window_main_buttons_init(struct window_main_s *window)
{
	window->button_join = gtk_button_new_with_label("Join");
	window->button_logout =gtk_button_new_with_label("Logout");
	window->button_create = gtk_button_new_with_label("Create");

	g_signal_connect(window->button_join, "clicked", window_main_button_join_cb, window);
	g_signal_connect(window->button_create, "clicked", window_main_button_create_cb, window);

	window->box_buttons = gtk_hbox_new(TRUE, 2);
	gtk_box_pack_start(window->box_buttons, window->button_join, TRUE, TRUE, 2);
	gtk_box_pack_start(window->box_buttons, window->button_create, TRUE, TRUE, 2);

}

void
window_main_tree_init(struct window_main_s *window)
{

	window->list_rooms = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
	window->tree_rooms = gtk_tree_view_new();
	gtk_tree_view_set_model(window->tree_rooms, GTK_TREE_MODEL(window->list_rooms));
	window->scrolled_rooms = gtk_scrolled_window_new(FALSE, FALSE);
	gtk_container_add(window->scrolled_rooms, window->tree_rooms);
}

void
window_main_init()
{
	struct window_main_s *window;

	window = g_malloc(sizeof(struct window_main_s));


	window_main_buttons_init(window);

	window_main_tree_init(window);

	window->box_main = gtk_vbox_new(FALSE, 2);
	gtk_box_pack_start(window->box_main, window->scrolled_rooms, TRUE, TRUE, 2);
	gtk_box_pack_start(window->box_main, window->box_buttons, FALSE, FALSE, 2);

	window->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_container_add(window->window, window->box_main);
	gtk_window_set_title(window->window, "Rooms");
	gtk_window_set_position(window->window, GTK_WIN_POS_CENTER);
	gtk_window_set_default_size(window->window, 500, 600);
	gtk_container_set_border_width(window->window, 2);
	gtk_widget_show_all(window->window);
}

